﻿using RuoVea.ExEnum;
using RuoVea.ExSugar.Attributes;
using RuoVea.ExSugar.Entity;
using SqlSugar;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace RuoVea.OmiApi.Article.Entitys;

/// <summary>
/// 分类表
/// </summary>
[SugarTable(nameof(ArtCategory), TableDescription = "分类表")]
[Description("分类表")]
[SugarIndex($"IX_{nameof(ArtCategory)}_{nameof(PId)}", nameof(PId), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(ArtCategory)}_{nameof(Code)}", nameof(Code), OrderByType.Asc, true)] // 唯一索引
[SugarIndex($"IX_{nameof(ArtCategory)}_{nameof(Sort)}", nameof(Sort), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(ArtCategory)}_{nameof(IsDisable)}", nameof(IsDisable), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(ArtCategory)}_{nameof(CreateTime)}", nameof(CreateTime), OrderByType.Desc)]
public class ArtCategory : EntityBase
{
    /// <summary>
    /// 父分类ID，0表示一级分类
    /// </summary>
    [ConfigSugarColumn(columnKey: nameof(PId), columnDescription: "父分类ID，0表示一级分类")]
    public long PId { get; set; }

    /// <summary>
    /// 名称
    /// </summary>
    [ConfigSugarColumn(columnKey: nameof(Name), columnDescription: "名称", Length = 64)]
    [Required, MaxLength(64)]
    public string Name { get; set; }

    /// <summary>
    /// 分类别名(URL友好格式)
    /// </summary>
    [ConfigSugarColumn(columnKey: nameof(Code), columnDescription: "编码，分类别名(URL友好格式)", Length = 200)]
    [Required, MaxLength(200)]
    public string Code { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    [ConfigSugarColumn(columnKey: nameof(Sort), columnDescription: "排序", IsNullable = true, DefaultValue = "10")]
    public int? Sort { get; set; } = 10;

    /// <summary>
    /// 备注
    /// </summary>
    [ConfigSugarColumn(columnKey: nameof(Remark), columnDescription: "备注", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)]
    [MaxLength(256)]
    public string Remark { get; set; }

    /// <summary>
    /// 状态-正常_0、停用_1 
    /// </summary>
    [ConfigSugarColumn(columnKey: nameof(IsDisable), columnDescription: "是否禁用", IsNullable = true)]
    public YesOrNot? IsDisable { get; set; } = YesOrNot.N;

    /// <summary>
    /// 导航属性 - 父分类（多对一关系）
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(PId))]
    [SugarColumn(IsIgnore = true)]
    public ArtCategory ParentCategory { get; set; }

    /// <summary>
    /// 导航属性 - 子分类列表（一对多关系）
    /// </summary>
    [Navigate(NavigateType.OneToMany, nameof(ArtCategory.PId))]
    [SugarColumn(IsIgnore = true)]
    public List<ArtCategory> Children { get; set; }

    /// <summary>
    /// 导航属性 - 文章列表（多对多关系，需要中间表）
    /// </summary>
    [Navigate(typeof(ArtCategoryArticle), nameof(ArtCategoryArticle.CategoryId), nameof(ArtCategoryArticle.ArticleId))]
    public List<ArtArticle> Articles { get; set; }
}